package com.example.mycarcalling.mytest;

import com.example.mycarcalling.bean.User;
import com.example.mycarcalling.service.NavigationService;
import com.example.mycarcalling.service.OrderService;
import com.example.mycarcalling.service.UserService;
import com.example.mycarcalling.vo.OrderWithNav;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class Servicett {

    @Resource
    private UserService userService;

    @Resource
    private OrderService orderService;

    @Resource
    private NavigationService navigationService;

    @Test
    public void getSellerOrderUserAddress(){
        User user = null;
        user =  userService.login("wei123456","123456");
        if (null==user){
            System.out.println("登录失败！");
        }else {
            System.out.println("登录成功！");
        }
    }

    public void changeNavigationAndOrder(){

    }

    @Test
    public void te1(){
        String locationDescribe = "在男生宿舍21栋附近";
        locationDescribe = locationDescribe.substring(0, locationDescribe.length() -1);
        locationDescribe = locationDescribe.substring(0, locationDescribe.length() -1);
        locationDescribe = locationDescribe.substring(1);
        System.out.println("去除后："+locationDescribe);
    }

    @Test
    public void te2(){
        List<OrderWithNav> orderWithNavs = navigationService.getDriverAllOrderNav(Long.valueOf(3));

        System.out.println(orderWithNavs);
    }

    @Test
    public void te3(){
        long nd = 1000 * 24 * 60 * 60;// 一天的毫秒数
        long nh = 1000 * 60 * 60;// 一小时的毫秒数
        long nm = 1000 * 60;// 一分钟的毫秒数
        long ns = 1000;// 一秒钟的毫秒数
        //格式化时间
        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            String date1 = "2021-5-12 17:30:10";
            String date2 = "2021-5-12 17:30:50";

            Date beginTime = simpleDateFormat.parse(date1);
            Date endTime = simpleDateFormat.parse(date2);
            long diff = endTime.getTime() - beginTime.getTime();
            System.out.println("diff:"+diff);
            double diff1 = diff;
            diff1 = diff1/(1000*60*60);
            System.out.println("diff1:"+String.format("%.3f",diff1));

            long hour = diff/nh;
            System.out.println("hour:"+hour);
            diff1 = hour;
            System.out.println(diff1);

            BigDecimal b = new BigDecimal(hour);
            long discount = b.setScale(3).longValue();

            System.out.println("discount:"+discount);

        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void te5(){
        DateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");
        String str = sdf.format(new Date());
        System.out.println("MM-dd HH:mm   "+str);
    }


}
